from django.db import models


# 系统用户模型
class SystemUser(models.Model):
    id = models.AutoField(primary_key=True)
    user_name = models.CharField(max_length=50)
    user_pass = models.CharField(max_length=100)
    nick_name = models.CharField(max_length=256, null=True)
    user_icon = models.TextField(null=True)

    def to_dict(self):
        res = {
            'id': self.id,
            'user_name': self.user_name,
            'user_pass': self.user_pass,
            'nick_name': self.nick_name,
            'user_icon': self.user_icon,
        }
        return res

    @staticmethod
    def get_fields():
        return [
            {'field': 'id', 'remark': 'id'},
            {'field': 'user_name', 'remark': '用户名', 'is_query': '1'},
            {'field': 'user_pass', 'remark': '密码', 'type': 'password'},
            {'field': 'nick_name', 'remark': '昵称'},
            {'field': 'user_icon', 'remark': '头像', 'type': 'images', 'not_save': '0'},
        ]

    class Meta:
        db_table = "system_user"
        app_label = "models"
